﻿using AuthCenter_HuangJingtao.Domain;
using AuthCenter_HuangJingtao.ErrorCode;
using AuthCenter_HuangJingtao.Infrastructure.Imterfaces;
using AuthCenter_HuangJingtao.Read.Api.Application.Command;
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace AuthCenter_HuangJingtao.Read.Api.Application.CommandHandler
{
    public class DelRoleCommandHandler : IRequestHandler<DelRoleCommand, ApiResult<int>>
    {
        IBaseReponsitory<Roles> Roles;

        public DelRoleCommandHandler(IBaseReponsitory<Roles> Roles)
        {
            this.Roles = Roles;
        }

        public async Task<ApiResult<int>> Handle(DelRoleCommand request, CancellationToken cancellationToken)
        {
            var list = await Roles.GetQuery().FirstOrDefaultAsync(c =>c.Role_Id == request.id);
            list.Role_IsDeleted = true;
            await Roles.UpdateAsync(list);
            return new ApiResult<int>
            {
                Code = ApiEnum.Success,
                Message = "删除成功",
                Data = 1

            };
        }
    }
}
